package aar.test.tessocr.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import aar.test.tessocr.interfaces.BaseAdapter;
import aar.test.tessocr.model.HistModel;
import aar.test.tessocr.model.OrderModel;
import com.idcheck.rechcustoms.R;

/**
 * author: sunshine
 * created on: 2023/9/25 16:25
 * description:
 */
public class HistListAdapter extends BaseAdapter<HistListAdapter.HistListItemHolder> {
    private List<HistModel> mList;
    private Context context;


    public HistListAdapter(Context mContext, @NonNull List<HistModel> mList) {
        this.mList = mList;
        this.context = mContext;
    }

    @Override
    public HistListAdapter.HistListItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.hist_list_item, parent, false);
        HistListAdapter.HistListItemHolder holder = new HistListAdapter.HistListItemHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull HistListAdapter.HistListItemHolder holder, final int position) {
        holder.tv_companyname.setText(mList.get(position).getCompany());
        holder.tv_companycode.setText(mList.get(position).getCode() );
        holder.tv_cabinetId.setText(mList.get(position).getCabinetId());
        holder.tv_gridnum.setText(mList.get(position).getGridnum());
        holder.tv_created_at.setText(mList.get(position).getCreated_at());
        holder.tv_updated_at.setText(mList.get(position).getUpdated_at());
        holder.tv_add_at.setText(mList.get(position).getAdd_at());


        holder.tv_open_hist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mViewClickListener) {
                    mViewClickListener.borrowKey(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class HistListItemHolder extends RecyclerView.ViewHolder {
        TextView tv_companyname;
        TextView tv_companycode;
        TextView tv_cabinetId;
        TextView tv_gridnum;
        TextView tv_created_at;
        TextView tv_updated_at;
        TextView tv_add_at;
        TextView tv_open_hist;


        public HistListItemHolder(View itemView) {
            super(itemView);
            tv_companyname = itemView.findViewById(R.id.tv_companyname);
            tv_companycode = itemView.findViewById(R.id.tv_companycode);
            tv_cabinetId = itemView.findViewById(R.id.tv_cabinetId);
            tv_gridnum = itemView.findViewById(R.id.tv_gridnum);
            tv_created_at = itemView.findViewById(R.id.tv_created_at);
            tv_updated_at = itemView.findViewById(R.id.tv_updated_at);
            tv_add_at = itemView.findViewById(R.id.tv_add_at);
            tv_open_hist = itemView.findViewById(R.id.tv_open_hist);
        }
    }

    public interface ViewClickListener {
        void borrowKey(int pos);
    }

    public void setViewClickListener(OrderListAdapter.ViewClickListener mViewClickListener) {
        this.mViewClickListener = mViewClickListener;

    }


    private OrderListAdapter.ViewClickListener mViewClickListener;
}
